<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--<el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['cld:temporary:add']"
        >新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>-->

    <el-table v-loading="loading" :data="temporaryList" @selection-change="handleSelectionChange" border>
      <el-table-column label="项目名称" align="center" prop="projectName" width="250px"/>
      <el-table-column label="发起人" align="center" prop="initiateName" width="120px"/>
      <el-table-column label="联系电话" align="center" prop="initiatePhone" width="120px"/>
      <el-table-column label="发起时间" align="center" prop="temporaryTime" width="160px">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.temporaryTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="工作内容" align="center" prop="temporaryContent" />
      <el-table-column label="受理人" align="center" prop="assignStaffName" width="120px"/>
      <el-table-column label="指派时间" align="center" prop="assignTime" width="160px">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.assignTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理人" align="center" prop="handleStaffName" width="300px"/>
      <el-table-column label="处理时间" align="center" prop="handleTime" width="160px">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.handleTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理内容" align="center" prop="handleContent" />
      <el-table-column label="处理状态" align="center" prop="handleStatus" width="120px">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.handleStatus == 0" type="info">未处理</el-tag>
          <el-tag v-if="scope.row.handleStatus == 1" type="primary">处理中</el-tag>
          <el-tag v-if="scope.row.handleStatus == 2" type="primary">已反馈</el-tag>
          <el-tag v-if="scope.row.handleStatus == 3" type="danger">已驳回</el-tag>
          <el-tag v-if="scope.row.handleStatus == 4" type="success">已完成</el-tag>
        </template>
      </el-table-column>
      <!--<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['cld:temporary:edit']"
          >修改</el-button>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>

    <!-- 添加或修改临时工作安排信息对话框 -->
    <!--<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目ID" prop="projectId">
          <el-input v-model="form.projectId" placeholder="请输入项目ID" />
        </el-form-item>
        <el-form-item label="发起时间" prop="temporaryTime">
          <el-date-picker clearable
            v-model="form.temporaryTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择发起时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="工作内容">
          <editor v-model="form.temporaryContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="项目账号信息ID" prop="projectAccountId">
          <el-input v-model="form.projectAccountId" placeholder="请输入项目账号信息ID" />
        </el-form-item>
        <el-form-item label="处理人ID" prop="assignStaffId">
          <el-input v-model="form.assignStaffId" placeholder="请输入处理人ID" />
        </el-form-item>
        <el-form-item label="指派时间" prop="assignTime">
          <el-date-picker clearable
            v-model="form.assignTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择指派时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理人ID" prop="handleStaffId">
          <el-input v-model="form.handleStaffId" placeholder="请输入处理人ID" />
        </el-form-item>
        <el-form-item label="处理时间" prop="handleTime">
          <el-date-picker clearable
            v-model="form.handleTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择处理时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理内容">
          <editor v-model="form.handleContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="解决描述" prop="sovleText">
          <el-input v-model="form.sovleText" placeholder="请输入解决描述" />
        </el-form-item>
        <el-form-item label="撤销描述" prop="revokeText">
          <el-input v-model="form.revokeText" placeholder="请输入撤销描述" />
        </el-form-item>
        <el-form-item label="驳回描述" prop="rejectText">
          <el-input v-model="form.rejectText" placeholder="请输入驳回描述" />
        </el-form-item>
        <el-form-item label="驳回时间" prop="rejectTime">
          <el-date-picker clearable
            v-model="form.rejectTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择驳回时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注是否关闭" prop="flag">
          <el-input v-model="form.flag" placeholder="请输入备注是否关闭" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>-->
  </div>
</template>

<script>
import { listTemporary, getTemporary, delTemporary, addTemporary, updateTemporary } from "@/api/cld/temporary";

export default {
  name: "Temporary",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 临时工作安排信息表格数据
      temporaryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询临时工作安排信息列表 */
    getList() {
      this.loading = true;
      listTemporary(this.queryParams).then(response => {
        this.temporaryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        temporaryId: null,
        projectId: null,
        temporaryTime: null,
        temporaryContent: null,
        temporaryImgs: null,
        projectAccountId: null,
        assignStaffId: null,
        assignTime: null,
        handleStaffId: null,
        handleTime: null,
        handleContent: null,
        handleStatus: null,
        handleImgs: null,
        sovleText: null,
        revokeText: null,
        rejectText: null,
        rejectImg: null,
        rejectTime: null,
        flag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.temporaryId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加临时工作安排信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const temporaryId = row.temporaryId || this.ids
      getTemporary(temporaryId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改临时工作安排信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.temporaryId != null) {
            updateTemporary(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTemporary(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const temporaryIds = row.temporaryId || this.ids;
      this.$modal.confirm('是否确认删除临时工作安排信息编号为"' + temporaryIds + '"的数据项？').then(function() {
        return delTemporary(temporaryIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('cld/temporary/export', {
        ...this.queryParams
      }, `temporary_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
